import {
  PageDetail
} from '../../config/api'
import util from '../../utils/util'

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    content: '',
    detail: {}, //详情对象
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log('options.id:', options.id);
    // console.log('详情页面：',JSON.parse(options.item));
    let that = this;
    this.setData({
      id: options.id
    })

    util.apiRequest(PageDetail, {
      id: options.id
    }, null).then(r => {
      console.log('详情页面数据：', r.data.data);
      let content = r.data.data.content.replace(/\<img/gi, '<img class="rich-img" ');
      that.setData({
        detail: r.data.data,
        content: content
      });
    });
  },

  onShareAppMessage: function (res) {
    console.log(res)
    if (res.from === 'button') { }
    return {
      title: this.data.detail.title,
      path: '/pages/newsDetail/newsDetail?id=' + this.data.id,
      success: function (res) {
        console.log('成功', res)
      }
    }
  }

})
